# Configure Hostname Permanently depending on distribution
if node[:przbase][:fqdn]

    if platform?("redhat", "centos", "fedora", "scientific", "amazon")
        ruby_block "Fix Hostname in /etc/sysconfig/network" do
            block do
                file = Chef::Util::FileEdit.new("/etc/sysconfig/network")
                file.search_file_replace_line(/^HOSTNAME/, "HOSTNAME=#{node[:przbase][:fqdn]}\n")
                file.write_file
            end
	not_if "egrep \"^HOSTNAME=#{node[:przbase][:fqdn]}$\" /etc/sysconfig/network "
        end
    #elif platform?("ubuntu", "debian")
    else
        file "/etc/hostname" do
            content "#{node[:przbase][:fqdn]}\n"
            mode "0644"
        end

    end

end


# Set current hostname
# FIXME: For some reason on this centos6.4 ohai returns node[:host]= as short hostname ... can't use to compare.
cHostname = Mixlib::ShellOut.new("hostname")
cHostname.run_command

execute "Set current hostname #{node[:przbase][:fqdn]}" do
    command "hostname #{node[:przbase][:fqdn]}"
    not_if { node[:przbase][:fqdn] == cHostname.stdout.chomp! }
end

